import os

ENV = os.getenv("ENV", "DEV")

STATIC_URL_PREFIX = "http://172.19.208.1:9999/static/"

SERVICE_DIR = "/etc/systemd/system/"

DATABASE_HOST = "172.19.208.1"
DATABASE_PORT = 3306
DATABASE_USER = "root"
DATABASE_PASSWORD = "123456"
DATABASE_SCHEMA = "brood2"

RABBITMQ_HOST = "172.19.208.1"
RABBITMQ_PORT = 5672
RABBITMQ_USER = "root"
RABBITMQ_PASSWORD = "123456"
RABBITMQ_QUEUE = "brood2"
RABBITMQ_VHOST = "brood2"

"""static package config*****************************************************************************"""


class Pkg:
    def __init__(self, url, extra_type):
        self.url = url
        self.extract_type = extra_type

    def __str__(self):
        return self.url


download_prefix = "http://172.19.208.1:8888"

DOCKER_PACKAGE = {
    "19": Pkg(download_prefix + "/docker-19.03.15.tgz", "tgz"),
    "20": Pkg(download_prefix + "/docker-20.10.24.tgz", "tgz"),
    "24": Pkg(download_prefix + "/docker-24.0.7.tgz", "tgz"),
}

ETCD_PACKAGE = {
    "3.5": Pkg(download_prefix + "/etcd-v3.5.8-linux-amd64.tar.gz", "tar.gz"),
}

KUBERNETES_PACKAGE = {
    "1.18": Pkg(download_prefix + "/kubernetes-server-linux-amd64-1.18.20.tar.gz", "tar.gz"),
    "1.20": Pkg(download_prefix + "/kubernetes-server-linux-amd64-1.20.15.tar.gz", "tar.gz"),
    "1.23": Pkg(download_prefix + "/kubernetes-server-linux-amd64-1.23.17.tar.gz", "tar.gz"),
    # "1.27": download_prefix+"/kubernetes-server-linux-amd64-1.27.8.tar.gz",  # todo runtime change
}

KUBECTL_CONVERT_PACKAGE = {
    "1.23": Pkg(download_prefix + "/kubernetes-plugins/kubectl-convert-1.23.17", "")
}

BASH_COMPLETION_PACKAGE = {
    "2.11": Pkg(download_prefix + "/bash-completion-2.11.tar.xz", "tar.xz")
}

NGINX_PACKAGE = {
    "1.14": Pkg(download_prefix + "/nginx-1.14.2.tar.gz", "tar.gz"),
    "1.16": Pkg(download_prefix + "/nginx-1.16.1.tar.gz", "tar.gz"),
    "1.18": Pkg(download_prefix + "/nginx-1.18.0.tar.gz", "tar.gz"),
    "1.20": Pkg(download_prefix + "/nginx-1.20.2.tar.gz", "tar.gz"),
    "1.24": Pkg(download_prefix + "/nginx-1.24.0.tar.gz", "tar.gz"),
}

# KEEPALIVED_PACKAGE = {
#     "2.1": Pkg(download_prefix+"/keepalived-2.1.5.tar.gz", "tar.gz"),
#     "2.2": Pkg(download_prefix+"/keepalived-2.2.8.tar.gz", "tar.gz"),
# }

OPENSSL_PACKAGE = {
    "1.1": Pkg(download_prefix + "/depend/openssl-1.1.1v.tar.gz", "tar.gz")
}

PCRE_PACKAGE = {
    "8.45": Pkg(download_prefix + "/depend/pcre-8.45.tar.bz2", "tar.bz2")
}

ZLIB_PACKAGE = {
    "1.3": Pkg(download_prefix + "/depend/zlib-1.3.tar.gz", "tar.gz")
}

NGINX_MODULE_VTS_PACKAGE = {
    "0.2.2": Pkg(download_prefix + "/depend/nginx-module-vts-0.2.2.tar.gz", "tar.gz")
}

"""image config*****************************************************************************"""
"""
docker pull docker/desktop-kubernetes-pause:3.9
"""
PAUSE_IMAGE = {
    "3.9":{
        "pause":"docker/desktop-kubernetes-pause:3.9"
    }
}


"""
docker.io/calico/cni:v3.27.0
docker.io/calico/node:v3.27.0
docker.io/calico/kube-controllers:v3.27.0
"""
CALICO_IMAGE = {
    "3.27": {
        "cni": "docker.io/calico/cni:v3.27.0",
        "node": "docker.io/calico/node:v3.27.0",
        "controller": "docker.io/calico/kube-controllers:v3.27.0",
    },
    "3.20": {
        "cni": "docker.io/calico/cni:v3.20.6",
        "node": "docker.io/calico/node:v3.20.6",
        "flexvol": "docker.io/calico/pod2daemon-flexvol:v3.20.6",
        "controller": "docker.io/calico/kube-controllers:v3.20.6"
    },
}

"""
coredns/coredns:1.9.4
"""
COREDNS_IMAGE = {
    "1.9": {
        "dns": "coredns/coredns:1.9.4",
    },
}

"""
registry.k8s.io/ingress-nginx/controller:v1.8.2
registry.k8s.io/ingress-nginx/kube-webhook-certgen:v20230407

registry.k8s.io/ingress-nginx/controller:v1.3.0
registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.1.1

quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0
"""
NGINX_INGRESS_IMAGE = {
    "1.8": {
        "controller": "registry.lank8s.cn/ingress-nginx/controller:v1.8.2",
        "webhook_certgen": "registry.lank8s.cn/ingress-nginx/kube-webhook-certgen:v20230407"
    },
    "1.3": {
        "controller": "registry.lank8s.cn/ingress-nginx/controller:v1.3.0",
        "webhook_certgen": "registry.lank8s.cn/ingress-nginx/kube-webhook-certgen:v1.1.1"
    },
    "0.30": {
        "controller": "quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0"
    },
}

"""print config"""
[print("{}={}".format(key, str(val))) for key, val in locals().items() if key == str(key).upper()]
